﻿using System.Media;
using System.IO;
using System.Reflection;

namespace ALDIOrganizer
{
    public static class Sounds
    {
        public const int Validated = 0;
        public const int Arpeggio = 1;
        public const int Pageturn = 2;
        public const int Logged = 3;

        private static readonly SoundPlayer[] Players;
        private static readonly Assembly Assembly;
        private static readonly Stream Stream;
        
        static Sounds()
        {
            Players = new SoundPlayer[4];
            Assembly = Assembly.GetExecutingAssembly();
            
            Stream = Assembly.GetManifestResourceStream("ALDIOrganizer.Resources.validated.wav");
            Stream.Seek(0, SeekOrigin.Begin);
            Players[Validated] = new SoundPlayer {Stream = Stream};

            Stream = Assembly.GetManifestResourceStream("ALDIOrganizer.Resources.arpeggio.wav");
            Stream.Seek(0, SeekOrigin.Begin);
            Players[Arpeggio] = new SoundPlayer {Stream = Stream};

            Stream = Assembly.GetManifestResourceStream("ALDIOrganizer.Resources.pageturn.wav");
            Stream.Seek(0, SeekOrigin.Begin);
            Players[Pageturn] = new SoundPlayer {Stream = Stream};

            Stream = Assembly.GetManifestResourceStream("ALDIOrganizer.Resources.lock.wav");
            Stream.Seek(0, SeekOrigin.Begin);
            Players[Logged] = new SoundPlayer {Stream = Stream};
        }

        public static void Play(int what)
        {
            if (!Program.PlaySounds)
            {
                return;
            }
            if (what == Arpeggio) // disables arpeggio sound: remove it!
            {
                return;
            }
            Players[what].Play();
        }
    }
}
